
using UnityEngine;
public class Database : MonoBehaviour
{
    public Item[] items;
    public Inventory[] inventories;

    private static Database instance;
    public static Database Instance
    {
        get
        {
            if (instance == null)
            {
                instance = FindObjectOfType<Database>();
            }
            return instance;
        }
    }

    private void Awake()
    {
        if (instance != null && instance != this)
        {
            Destroy(gameObject);
            return;
        }
        instance = this;
        DontDestroyOnLoad(gameObject);
    }

    public Item GetItemByName(string name)
    {
        if (items == null || items.Length == 0)
            return null;
        for (int i = 0; i < items.Length; i++)
        {
            if (items[i] != null && items[i].name == name)
                return items[i];
        }
        return null;
    }
    public Inventory GetInventoryByName(string name)
    {
        if (inventories == null || inventories.Length == 0)
            return null;
        for (int i = 0; i < inventories.Length; i++)
        {
            if (inventories[i] != null && inventories[i].name == name)
                return inventories[i];
        }
        return null;
    }
}
